package com.lehe.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.lehe.dao.AdminRoleDao;
import com.lehe.dao.XHUserListDao;
import com.lehe.entry.AdminRoleDto;
import com.lehe.entry.page.PageDto;
import com.lehe.entry.xh.UserDto;

/**
 * 用户列表页面相关Controller
 * @author Administrator
 *
 */
@RequestMapping("admin/userList")
@Controller
public class XHUserListController extends BaseAdminController {

	@Autowired
	private XHUserListDao xHUserListDao;
	
	@Autowired
	private AdminRoleDao adminRoleDao;
	
	@RequestMapping("page")
	public String userList(Model m,@RequestParam(required=false)Long topId){
		m.addAttribute("topId",topId);
		return "admin/xh_userList/userList";
	}
	
	@RequestMapping("pageList")
	public String userListData(
			@RequestParam(required=false)String queryStr,
			@RequestParam(required=false)Integer page,
			@RequestParam(required=false)Long parentId,
			@RequestParam(required=false)String level,
			@RequestParam(required=false)Long topId,
			String sd,String ed,
			@RequestParam(required=false)String orderBy,
			@RequestParam(required=false)Integer pageSize,Model m){
		
		List<UserDto> list = null;
		Integer count = null;
		PageDto pd = new PageDto(page,pageSize);
		
		
		AdminRoleDto roleDto = adminRoleDao.queryById(this.getAdminUserRoleId());
        if(roleDto.getName().equals("运营号")){
        	topId = this.getAdminUserId();
        }
		
		list = xHUserListDao.queryUserList(queryStr,topId,null,parentId,sd,ed,level, orderBy, pd.getPageIndex(), pd.getPageSize());
		count = xHUserListDao.queryUserListCount(queryStr,topId,null,parentId, level);
		
		m.addAttribute("parentId",parentId);
		m.addAttribute("data",list);
		pd.setRecordCount(count);
		m.addAttribute("page",pd);
		m.addAttribute("queryStr",queryStr);
		m.addAttribute("level",level);
		m.addAttribute("sd",sd);
		m.addAttribute("ed",ed);
		
		return "admin/xh_userList/userListList";
	}
}
